package org.wyq.myweb.config;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


@Component("beanConfig")
public class BeanConfig {
	private BeanConfig(){
	}
	
	private static ApplicationContext context;
	
	public static ApplicationContext getContext(){
		return context;
	}
	
	@Autowired
	@Required
	private void setContext(ApplicationContext context) {
		BeanConfig.context = context;
	}

	public static Object getBean(String name) {
		return context.getBean(name);
	}

	public static <T> T getBean(String name, Class<T> requiredType) {
		return context.getBean(name, requiredType);
	}

	public static <T> T getBean(Class<T> requiredType) {
		return context.getBean(requiredType);
	}

}
